package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.service.wx.WxFootprintService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.wx.wtz.FootprintVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: wutanzi
 * @Date: 2023/5/23 下午4:15
 * @Version: v1.0.0
 * @Description: 足迹Controller, 装配足迹服务
 * 转载安全措施
 * 以及list delete
 **/
@RestController
@RequestMapping("/wx/footprint")
public class WxFootprintController {
    @Autowired
    WxFootprintService userFootprintService;
//    @Autowired
//    SecurityManager securityManager;

    @GetMapping("/list")
    public Object list(Integer page, Integer limit) {
        //获取用户id
//        Integer userId = SessionUtil.getUserId(securityManager);
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        Integer userId = (Integer) session.getAttribute("userId");
        List<FootprintVo> result = userFootprintService.list(userId, page, limit);

        return ResponseUtil.okList(result);

    }

    @PostMapping("/delete")
    public Object delete(@RequestBody HashMap<String, Integer> paramsMap, Integer page, Integer limit) {
        //获取用户id
//        Integer userId = SessionUtil.getUserId(securityManager);
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        Integer userId = (Integer) session.getAttribute("userId");
        //获取足迹id
        Integer footprintId = paramsMap.get("id");
        int resCode = userFootprintService.delete(userId, footprintId);
        if (resCode == 1) {
            return ResponseUtil.ok();
        } else {
            return ResponseUtil.fail();
        }

    }


}
